# -*- coding: utf-8 -*-
'''
@author: Hugo
@file: taobao_mitmproxy.py
@time: 2021/9/28 11:30
'''
from mitmproxy import ctx
from icecream import ic
from lxml import etree
# import mongodb

def response(flow):
    # 获取响应对象
    url = flow.request.url
    ic(url)
    if 'https://s.taobao.com/search?initiative_id=tbindexz_20170306&ie=utf8&spm=a21bo.21814703.201856-taobao-item.2&sourceId=tb.index&search_type=item&ssid=s5-e&commend=all&imgfile=&q=%E4%B9%90%E9%AB%98%E7%A7%AF%E6%9C%A8&suggest=0_2&_input_charset=utf-8&wq=lega&suggest_query=lega&source=suggest' not in url:
        return
    html = flow.response.text
    res = etree.HTML(html)
    ic(type(res))
    data = res.xpath('//div[@class="m-itemlist"]/div/div/div/div/div/a/text()')
    ic(data)
    # for i in data:
    #     title = i.xpath('./div[@class="row row-2 title"]/a/text()')
    #     price = i.xpath('./div[@class="ctx-box J_MouseEneterLeave J_IconMoreNew"]/div/div/strong/text()')
    #     merchant = i.xpath('./div[@class="row row-3 g-clearfix"]/div/a/span/text()')
    #     location = i.xpath('./div[@class="row row-3 g-clearfix"]/div[@class="location"]/text()')
    #     pay_count = i.xpath('./div[@class="row row-1 g-clearfix"]/div[@class="deal-cnt"]/text()')
    #     ic(title)




